$(document).ready(function () {
    queryProject()
});

//查询所有社会实践
function queryProject() {
    var table = $('#dataTable').dataTable()
    if (table) {
        table.fnDestroy();
    }
    $('#dataTable').dataTable({
        "bDeferRender": true,
        "sAjaxDataProp": "data.projectList",
        "sAjaxSource": "http://localhost:8080/finishProject/findAgreedProjectByTea",
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function (oSettings) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>"
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",
        "aoColumnDefs": [
            {
                "mDataProp": null,
                "sDefaultContent": "<a href='#'><span id='check'>查看</span></a>",
                "aTargets": [-1]
            }
        ],
        "aoColumns": [
            {"mDataProp": "projectId"},
            {"mDataProp": "stuNum"},
            {"mDataProp": "stuName"},
            {"mDataProp": "termYear"},
            {"mDataProp": "termNum"},
            {"mDataProp": "projectName"},
            {"mDataProp": "projectContent"},
            {"mDataProp": "projectStartDate"},
            {"mDataProp": "projectEndtDate"},
            {"mDataProp": "projectPlatform"},
            {
                "mDataProp": "projectState",
                "mRender": function (data) {
                    if (data == 3) {
                        value = "<span id='edit-btn' class='badge badge-info mr10 mb10'>已通过</span>";
                    }
                    if (data == 4) {
                        value = "<span id='edit-btn' class='badge badge-warning mr10 mb10'>已拒绝</span>";
                    }
                    if (data == 5) {
                        value = "<a href='#'><span id='refuse' class='label label-danger mr10 mb10' >拒绝</span></a>" +
                            "<a href='#'><span id='agree' class='label label-yellow mr10 mb10'>通过</span></a>";
                    }

                    return value;
                }
            },
            {"mDataProp": ""},

        ],

    })
}

$(document).on('click', '#check', function () {
    //获取projectId
    var projectId = $(this).parents("tr").children(0).eq(0).text();
    location.href="detailFinishProject.html?projectId="+projectId;

})

//拒绝
$(document).on('click', '#refuse', function () {
    var projectId = $(this).parents("tr").children(0).eq(0).text();
    var projectState = 4;
    $.ajax({
        url: "http://localhost:8080/finishProject/updateFinishProject",
        type: "GET",
        data: "projectId=" + projectId + "&projectState=" + projectState,
        dataType: "json",
        success: function (data) {
            var msg = "申请成功！请耐心等待！";
            $.each(data.data, function (key, value) {
                msg = value;
            });
            window.location.reload();
            layer.msg(msg);
        },
        error: function () {
            layer.msg("网络在开小差~稍后重试");
        }
    });
})
//通过
$(document).on('click', '#agree', function () {
    var projectId = $(this).parents("tr").children(0).eq(0).text();
    var projectState = 3;
    $.ajax({
        url: "http://localhost:8080/finishProject/updateFinishProject",
        type: "GET",
        data: "projectId=" + projectId + "&projectState=" + projectState,
        dataType: "json",
        success: function (data) {
            var msg = "申请成功！请耐心等待！";
            $.each(data.data, function (key, value) {
                msg = value;
            });
            window.location.reload();
            layer.msg(msg);
        },
        error: function () {
            layer.msg("网络在开小差~稍后重试");
        }
    })
})

//条件查询社会实践

$(document).on('click', '#selectProjext', function () {
    alert("----")
    var stuNum = $("#stuNum").val();
    var stuName = $("#stuName").val();
    var termYear = $("#termYear option:selected").val();
    var termNum = $("#termNum option:selected").val();
    var projectState = $("#state option:selected").val();
    var url = "http://localhost:8080/finishProject/queryProject?stuNum=" + stuNum + "&stuName=" + stuName +
        "&termYear=" + termYear + "&termNum=" + termNum + "&projectState=" + projectState;

    var table = $('#dataTable').dataTable()
    if (table) {
        table.fnDestroy();
    }
    $('#dataTable').dataTable({
        "bDeferRender": true,
        "sAjaxDataProp": "data.projectList",
        "sAjaxSource": url,
        "sPaginationType": "bs_full", //"bs_normal", "bs_two_button", "bs_four_button", "bs_full"
        "fnPreDrawCallback": function (oSettings) {
            $('.dataTables_filter input').addClass('form-control input-large').attr('placeholder', 'Search');
            $('.dataTables_length select').addClass('form-control input-small');
        },
        "oLanguage": {
            "sSearch": "",
            "sLengthMenu": "<span>_MENU_ entries</span>"
        },
        "bJQueryUI": false,
        "bAutoWidth": false,
        "sDom": "<'row'<'col-lg-6 col-md-6 col-sm-12 text-center'l><'col-lg-6 col-md-6 col-sm-12 text-center'f>r>t<'row-'<'col-lg-6 col-md-6 col-sm-12'i><'col-lg-6 col-md-6 col-sm-12'p>>",
        "aoColumnDefs": [
            {
                "mDataProp": null,
                "sDefaultContent": "<a href='#'>查看</a>",
                "aTargets": [-1]
            }
        ],
        "aoColumns": [
            {"mDataProp": "projectId"},
            {"mDataProp": "stuNum"},
            {"mDataProp": "stuName"},
            {"mDataProp": "termYear"},
            {"mDataProp": "termNum"},
            {"mDataProp": "projectName"},
            {"mDataProp": "projectContent"},
            {"mDataProp": "projectStartDate"},
            {"mDataProp": "projectEndtDate"},
            {"mDataProp": "projectPlatform"},
            {
                "mDataProp": "projectState",
                "mRender": function (data) {
                    if (data == 3) {
                        value = "<span id='edit-btn' class='badge badge-info mr10 mb10'>已通过</span>";
                    }
                    if (data == 4) {
                        value = "<span id='edit-btn' class='badge badge-warning mr10 mb10'>已拒绝</span>";
                    }
                    if (data == 5) {
                        value = "<a href='#'><span id='refuse' class='label label-danger mr10 mb10' >拒绝</span></a>" +
                            "<a href='#'><span id='agree' class='label label-yellow mr10 mb10'>通过</span></a>";
                    }
                    return value;
                }
            },
            {"mDataProp": ""},

        ],

    })
})


